﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Tests
//  File name:	TestQueryBuilder.cs
//  Developer:	Solomatov Igor
//  Created:	03.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Smart.Common.Entities;

namespace Smart.Documents.Tests
{
	[TestClass]
	public class TestQueryBuilder
	{
		[TestMethod]
		public void QueryBuilderItem()
		{
			var i1 = new CamlQueryBuilderConditionItem<Entity>("id", "op", "vt", "val");
			var i2 = new CamlQueryBuilderConditionItem<Entity>("fld", "op", "integer", "val");
			var i3 = new CamlQueryBuilderConditionItem<Entity>("id", "op", "integer", "val");

			Assert.AreEqual(@"<op><FieldRef Name=""id""/><Value Type=""vt"">val</Value></op>", i1.FormatQuery());
			Assert.AreEqual(@"<op><FieldRef Name=""fld""/><Value Type=""integer"">val</Value></op>", i2.FormatQuery());
			Assert.AreEqual(@"<op><FieldRef Name=""id""/><Value Type=""Counter"">val</Value></op>", i3.FormatQuery());

			var o1 = new CamlQueryBuilderDateRangesOverlapItem<Entity>("fsd", "fed", "frid", "sv");
			var o2 = new CamlQueryBuilderDateRangesOverlapItem<Entity>("fsd", "fed", "frid", true, new DateTime(2011, 10, 09, 8, 7, 6));
			var o3 = new CamlQueryBuilderDateRangesOverlapItem<Entity>("fsd", "fed", "frid", false, new DateTime(2011, 10, 09, 8, 7, 6));

			Assert.AreEqual(
				@"<DateRangesOverlap><FieldRef Name=""fsd""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""FALSE"">sv</Value></DateRangesOverlap>",
				o1.FormatQuery());
			Assert.AreEqual(
				@"<DateRangesOverlap><FieldRef Name=""fsd""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""TRUE"">2011-10-09T08:07:06Z</Value></DateRangesOverlap>",
				o2.FormatQuery());
			Assert.AreEqual(
				@"<DateRangesOverlap><FieldRef Name=""fsd""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""FALSE"">2011-10-09T08:07:06Z</Value></DateRangesOverlap>",
				o3.FormatQuery());

			var s1 = new CamlQueryBuilderStatementItem<Entity>("fld", "CHECK=\"TRUE\"", "op", "stmt");
			var s2 = new CamlQueryBuilderStatementItem<Entity>("fld", null, "op", "stmt");
			var s3 = new CamlQueryBuilderStatementItem<Entity>(null, null, null, "stmt");

			Assert.AreEqual(@"<op><FieldRef Name=""fld"" CHECK=""TRUE""/>stmt</op>", s1.FormatQuery());
			Assert.AreEqual(@"<op><FieldRef Name=""fld""/>stmt</op>", s2.FormatQuery());
			Assert.AreEqual(@"stmt", s3.FormatQuery());

			var m1 = new CamlQueryBuilderMembershipItem<Entity>("fld", MembershipType.CurrentUserGroups);

			Assert.AreEqual(@"<Membership Type=""CurrentUserGroups""><FieldRef Name=""fld""/></Membership>", m1.FormatQuery());

			var in1 = new CamlQueryBuilderInItem<Entity>("fld", "integer", "v1", "v2", "v3");
			var in2 = new CamlQueryBuilderInItem<Entity>("id", "integer", "v1", "v2", "v3");
			var in3 = new CamlQueryBuilderInItem<Entity>("id", "text", "v1", "v2", "v3");

			Assert.AreEqual(@"<In><FieldRef Name=""fld""/><Values><Value Type=""integer"">v1</Value><Value Type=""integer"">v2</Value><Value Type=""integer"">v3</Value></Values></In>",
							in1.FormatQuery());
			Assert.AreEqual(@"<In><FieldRef Name=""id""/><Values><Value Type=""Counter"">v1</Value><Value Type=""Counter"">v2</Value><Value Type=""Counter"">v3</Value></Values></In>",
							in2.FormatQuery());
			Assert.AreEqual(@"<In><FieldRef Name=""id""/><Values><Value Type=""text"">v1</Value><Value Type=""text"">v2</Value><Value Type=""text"">v3</Value></Values></In>",
							in3.FormatQuery());

			var or1 = new CamlQueryBuilderOrderItem<Entity>("fld", "DESC");
			var or2 = new CamlQueryBuilderOrderItem<Entity>("fld", "DeSC");
			var or3 = new CamlQueryBuilderOrderItem<Entity>("fld", "ASC");
			var or4 = new CamlQueryBuilderOrderItem<Entity>("fld", "aSC");

			Assert.AreEqual(@"<FieldRef Name=""fld"" Ascending=""FALSE"" />", or1.FormatQuery());
			Assert.AreEqual(@"<FieldRef Name=""fld"" Ascending=""FALSE"" />", or2.FormatQuery());
			Assert.AreEqual(@"<FieldRef Name=""fld"" Ascending=""TRUE"" />", or3.FormatQuery());
			Assert.AreEqual(@"<FieldRef Name=""fld"" Ascending=""TRUE"" />", or4.FormatQuery());

			var gr1 = new CamlQueryBuilderGroupItem<Entity>("fld");

			Assert.AreEqual(@"<FieldRef Name=""fld"" />", gr1.FormatQuery());
		}

		[TestMethod]
		public void QueryBuilderCache()
		{
		}

		[TestMethod]
		public void QueryBuilderGroups()
		{
			var ccg1 = new CamlQueryBuilderConditionGroup<Entity>("cgop", true, true);
			var ccg1r1 = ccg1
				.BeginsWith("fld1", "bwt")
				.Contains("fld2", "ct")
				.DateRangesOverlap("fsd3", "fed", "frid", DateRangesOverlapValue.Month)
				.DateRangesOverlap("fsd4", "fed", "frid", DateRangesOverlapValue.Now)
				.And
				.Eq("fsd5", true)
				.Eq("fsd6.1", new DateTime(2012, 11, 10, 15, 30, 00))
				.Eq("fsd6.2", new DateTime(2012, 11, 10, 15, 30, 00), true)
				.Eq("fsd7", 0.7)
				.Eq("fsd8", 10)
				.End
				.Or
				.EqL("fsd9", 15)
				.EqU("fsd1")
				.EqU("fsd2", 20)
				.Filter("fsd3", FilterCondition.Leq, 1)
				.End
				.And
				.End
				.Or
				.Filter("fsd4", FilterCondition.Eq, new DateTime(2012, 11, 10, 15, 30, 05), true)
				.End
				.And
				.Or
				.And
				.Filter("fsd5", FilterCondition.In, new[] { "v1", "v2", "v3" })
				.Filter("id", FilterCondition.In, new[] { 1, 5, 7, 2 })
				.Geq("fsd1", 13.5)
				.Gt("fsd2", 13)
				.In("fsd3", new[] { new DateTime(2012, 11, 10, 15, 30, 01), new DateTime(2012, 11, 10, 15, 30, 02), new DateTime(2012, 11, 10, 15, 30, 00) })
				.End
				.And
				.Includes("fld1", 10)
				.Includes("fld2", "text")
				.End
				.End
				.Or
				.IncludesU("fld3", 5)
				.IsNotNull("fld4")
				.IsNull("fld5")
				.Leq("fld6", 5)
				.Lt("fld7", 10)
				.Membership("fld8", MembershipType.Groups)
				.Neq("fld9", true)
				.End
				.End
				.NeqL("fld1", 100)
				.NeqU("fld2", 10)
				.NeqU("fld3")
				.NotIncludes("fld4", 10)
				.NotIncludes("fld5", "txt")
				.NotIncludesU("fld6")
				.NotIncludesU("fld7", 10)
				.FormatQuery();

			var ccg1r2 = new CamlQueryBuilderConditionGroup<Entity>("cgop", true, true).FormatQuery();
			var ccg1r3 = new CamlQueryBuilderConditionGroup<Entity>("cgop", true, false).Eq("fld", "<text/>").FormatQuery();
			var ccg1r4 = new CamlQueryBuilderConditionGroup<Entity>("cgop", true, true).Eq("fld", "<text/>").FormatQuery();

			Assert.AreEqual(
				@"<cgop><cgop><cgop><cgop><BeginsWith><FieldRef Name=""fld1""/><Value Type=""Text"">bwt</Value></BeginsWith><Contains><FieldRef Name=""fld2""/><Value Type=""Text"">ct</Value></Contains></cgop><cgop><DateRangesOverlap><FieldRef Name=""fsd3""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""FALSE"">Month</Value></DateRangesOverlap><DateRangesOverlap><FieldRef Name=""fsd4""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""TRUE"">Now</Value></DateRangesOverlap></cgop></cgop><cgop><cgop><And><And><And><Eq><FieldRef Name=""fsd5""/><Value Type=""Boolean"">1</Value></Eq><Eq><FieldRef Name=""fsd6.1""/><Value Type=""DateTime"">2012-11-10T15:30:00Z</Value></Eq></And><And><Eq><FieldRef Name=""fsd6.2""/><Value Type=""DateTime"" IncludeTimeValue=""TRUE"">2012-11-10T15:30:00Z</Value></Eq><Eq><FieldRef Name=""fsd7""/><Value Type=""Number"">0.7</Value></Eq></And></And><Eq><FieldRef Name=""fsd8""/><Value Type=""Integer"">10</Value></Eq></And><Or><Or><Eq><FieldRef Name=""fsd9"" LookupId=""TRUE""/><Value Type=""Lookup"">15</Value></Eq><Eq><FieldRef Name=""fsd1"" LookupId=""TRUE""/><Value Type=""Lookup""><UserID/></Value></Eq></Or><Or><Eq><FieldRef Name=""fsd2"" LookupId=""TRUE""/><Value Type=""Lookup"">20</Value></Eq><Leq><FieldRef Name=""fsd3""/><Value Type=""Integer"">1</Value></Leq></Or></Or></cgop><cgop><Eq><FieldRef Name=""fsd4""/><Value Type=""DateTime"" IncludeTimeValue=""TRUE"">2012-11-10T15:30:05Z</Value></Eq></cgop></cgop></cgop><cgop><cgop><cgop><And><Or><And><And><And><In><FieldRef Name=""fsd5""/><Values><Value Type=""Text"">v1</Value><Value Type=""Text"">v2</Value><Value Type=""Text"">v3</Value></Values></In><In><FieldRef Name=""id""/><Values><Value Type=""Counter"">1</Value><Value Type=""Counter"">5</Value><Value Type=""Counter"">7</Value><Value Type=""Counter"">2</Value></Values></In></And><And><Geq><FieldRef Name=""fsd1""/><Value Type=""Number"">13.5</Value></Geq><GT><FieldRef Name=""fsd2""/><Value Type=""Integer"">13</Value></GT></And></And><In><FieldRef Name=""fsd3""/><Values><Value Type=""DateTime"">2012-11-10T15:30:01Z</Value><Value Type=""DateTime"">2012-11-10T15:30:02Z</Value><Value Type=""DateTime"">2012-11-10T15:30:00Z</Value></Values></In></And><And><Includes><FieldRef Name=""fld1"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></Includes><Includes><FieldRef Name=""fld2""/><Value Type=""Text"">text</Value></Includes></And></Or><Or><Or><Or><Includes><FieldRef Name=""fld3"" LookupId=""TRUE""/><Value Type=""Lookup"">5</Value></Includes><IsNotNull><FieldRef Name=""fld4""/></IsNotNull></Or><Or><IsNull><FieldRef Name=""fld5""/></IsNull><Leq><FieldRef Name=""fld6""/><Value Type=""Integer"">5</Value></Leq></Or></Or><Or><Or><LT><FieldRef Name=""fld7""/><Value Type=""Integer"">10</Value></LT><Membership Type=""Groups""><FieldRef Name=""fld8""/></Membership></Or><Neq><FieldRef Name=""fld9""/><Value Type=""Boolean"">1</Value></Neq></Or></Or></And><Neq><FieldRef Name=""fld1"" LookupId=""TRUE""/><Value Type=""Lookup"">100</Value></Neq></cgop><cgop><Neq><FieldRef Name=""fld2"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></Neq><Neq><FieldRef Name=""fld3"" LookupId=""TRUE""/><Value Type=""Lookup""><UserID/></Value></Neq></cgop></cgop><cgop><cgop><NotIncludes><FieldRef Name=""fld4"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></NotIncludes><NotIncludes><FieldRef Name=""fld5""/><Value Type=""Text"">txt</Value></NotIncludes></cgop><cgop><NotIncludes><FieldRef Name=""fld6"" LookupId=""TRUE""/><Value Type=""Lookup""><UserID/></Value></NotIncludes><NotIncludes><FieldRef Name=""fld7"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></NotIncludes></cgop></cgop></cgop></cgop>",
				ccg1r1);
			Assert.AreEqual(@"", ccg1r2);
			Assert.AreEqual(@"<Eq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;</Value></Eq>", ccg1r3);
			Assert.AreEqual(@"<cgop><Eq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;</Value></Eq></cgop>", ccg1r4);

			var ccg2 = new CamlQueryBuilderConditionGroup<Entity>("cgop", false, true);
			var ccg2r1 = ccg2
				.BeginsWith("fld1", "bwt")
				.Contains("fld2", "ct")
				.DateRangesOverlap("fsd3", "fed", "frid", DateRangesOverlapValue.Month)
				.DateRangesOverlap("fsd4", "fed", "frid", DateRangesOverlapValue.Now)
				.And
				.Eq("fsd5", true)
				.Eq("fsd6.1", new DateTime(2012, 11, 10, 15, 30, 00))
				.Eq("fsd6.2", new DateTime(2012, 11, 10, 15, 30, 00), false)
				.Eq("fsd7", 0.7)
				.Eq("fsd8", 10)
				.End
				.Or
				.EqL("fsd9", 15)
				.EqU("fsd1")
				.EqU("fsd2", 20)
				.Filter("fsd3", FilterCondition.Leq, 1)
				.End
				.Or
				.End
				.And
				.Filter("fsd4", FilterCondition.Eq, new DateTime(2012, 11, 10, 15, 30, 05), true)
				.End
				.And
				.Or
				.And
				.Filter("fsd5", FilterCondition.In, new[] { "v1", "v2", "v3" })
				.Filter("id", FilterCondition.In, new[] { 1, 5, 7, 2 })
				.Geq("fsd1", -13.5)
				.Gt("fsd2", -13)
				.In("fsd3", new[] { new DateTime(2012, 11, 10, 15, 30, 01), new DateTime(2012, 11, 10, 15, 30, 02), new DateTime(2012, 11, 10, 15, 30, 00) })
				.End
				.And
				.Includes("fld1", 10)
				.Includes("fld2", "text")
				.End
				.End
				.Or
				.IncludesU("fld3", 5)
				.IsNotNull("fld4")
				.IsNull("fld5")
				.Leq("fld6", 5)
				.Lt("fld7", 10)
				.Membership("fld8", MembershipType.Groups)
				.Neq("fld9", false)
				.End
				.End
				.NeqL("fld1", 100)
				.NeqU("fld2", 10)
				.NeqU("fld3")
				.NotIncludes("fld4", 10)
				.NotIncludes("fld5", "txt")
				.NotIncludesU("fld6")
				.NotIncludesU("fld7", 10)
				.FormatQuery();

			var ccg2r2 = new CamlQueryBuilderConditionGroup<Entity>("cgop", false, true).FormatQuery();
			var ccg2r3 = new CamlQueryBuilderConditionGroup<Entity>("cgop", false, false).Eq("fld", "<text/>").FormatQuery();
			var ccg2r4 = new CamlQueryBuilderConditionGroup<Entity>("cgop", false, true).Eq("fld", "<text/>").FormatQuery();

			Assert.AreEqual(
				@"<cgop><BeginsWith><FieldRef Name=""fld1""/><Value Type=""Text"">bwt</Value></BeginsWith><Contains><FieldRef Name=""fld2""/><Value Type=""Text"">ct</Value></Contains><DateRangesOverlap><FieldRef Name=""fsd3""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""FALSE"">Month</Value></DateRangesOverlap><DateRangesOverlap><FieldRef Name=""fsd4""/><FieldRef Name=""fed""/><FieldRef Name=""frid""/><Value Type=""DateTime"" IncludeTimeValue=""TRUE"">Now</Value></DateRangesOverlap><And><And><And><Eq><FieldRef Name=""fsd5""/><Value Type=""Boolean"">1</Value></Eq><Eq><FieldRef Name=""fsd6.1""/><Value Type=""DateTime"">2012-11-10T15:30:00Z</Value></Eq></And><And><Eq><FieldRef Name=""fsd6.2""/><Value Type=""DateTime"" IncludeTimeValue=""FALSE"">2012-11-10T15:30:00Z</Value></Eq><Eq><FieldRef Name=""fsd7""/><Value Type=""Number"">0.7</Value></Eq></And></And><Eq><FieldRef Name=""fsd8""/><Value Type=""Integer"">10</Value></Eq></And><Or><Or><Eq><FieldRef Name=""fsd9"" LookupId=""TRUE""/><Value Type=""Lookup"">15</Value></Eq><Eq><FieldRef Name=""fsd1"" LookupId=""TRUE""/><Value Type=""Lookup""><UserID/></Value></Eq></Or><Or><Eq><FieldRef Name=""fsd2"" LookupId=""TRUE""/><Value Type=""Lookup"">20</Value></Eq><Leq><FieldRef Name=""fsd3""/><Value Type=""Integer"">1</Value></Leq></Or></Or><Eq><FieldRef Name=""fsd4""/><Value Type=""DateTime"" IncludeTimeValue=""TRUE"">2012-11-10T15:30:05Z</Value></Eq><And><Or><And><And><And><In><FieldRef Name=""fsd5""/><Values><Value Type=""Text"">v1</Value><Value Type=""Text"">v2</Value><Value Type=""Text"">v3</Value></Values></In><In><FieldRef Name=""id""/><Values><Value Type=""Counter"">1</Value><Value Type=""Counter"">5</Value><Value Type=""Counter"">7</Value><Value Type=""Counter"">2</Value></Values></In></And><And><Geq><FieldRef Name=""fsd1""/><Value Type=""Number"">-13.5</Value></Geq><GT><FieldRef Name=""fsd2""/><Value Type=""Integer"">-13</Value></GT></And></And><In><FieldRef Name=""fsd3""/><Values><Value Type=""DateTime"">2012-11-10T15:30:01Z</Value><Value Type=""DateTime"">2012-11-10T15:30:02Z</Value><Value Type=""DateTime"">2012-11-10T15:30:00Z</Value></Values></In></And><And><Includes><FieldRef Name=""fld1"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></Includes><Includes><FieldRef Name=""fld2""/><Value Type=""Text"">text</Value></Includes></And></Or><Or><Or><Or><Includes><FieldRef Name=""fld3"" LookupId=""TRUE""/><Value Type=""Lookup"">5</Value></Includes><IsNotNull><FieldRef Name=""fld4""/></IsNotNull></Or><Or><IsNull><FieldRef Name=""fld5""/></IsNull><Leq><FieldRef Name=""fld6""/><Value Type=""Integer"">5</Value></Leq></Or></Or><Or><Or><LT><FieldRef Name=""fld7""/><Value Type=""Integer"">10</Value></LT><Membership Type=""Groups""><FieldRef Name=""fld8""/></Membership></Or><Neq><FieldRef Name=""fld9""/><Value Type=""Boolean"">0</Value></Neq></Or></Or></And><Neq><FieldRef Name=""fld1"" LookupId=""TRUE""/><Value Type=""Lookup"">100</Value></Neq><Neq><FieldRef Name=""fld2"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></Neq><Neq><FieldRef Name=""fld3"" LookupId=""TRUE""/><Value Type=""Lookup""><UserID/></Value></Neq><NotIncludes><FieldRef Name=""fld4"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></NotIncludes><NotIncludes><FieldRef Name=""fld5""/><Value Type=""Text"">txt</Value></NotIncludes><NotIncludes><FieldRef Name=""fld6"" LookupId=""TRUE""/><Value Type=""Lookup""><UserID/></Value></NotIncludes><NotIncludes><FieldRef Name=""fld7"" LookupId=""TRUE""/><Value Type=""Lookup"">10</Value></NotIncludes></cgop>",
				ccg2r1);
			Assert.AreEqual(@"", ccg2r2);
			Assert.AreEqual(@"<Eq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;</Value></Eq>", ccg2r3);
			Assert.AreEqual(@"<cgop><Eq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;</Value></Eq></cgop>", ccg2r4);

			var ccg3r1 =
				new CamlQueryBuilderConditionGroup<Entity>("cgop", false, true).Eq("fld", "<text/>\"\\'").Neq("fld", "<text/>\"\\'").Contains("fld", "<text/>\"\\'").BeginsWith("fld",
																																												"<text/>\"\\'").
					In("fld", "<text/>\"\\'").In("fld", "<text1/>\"\\'", "<text2/>\"\\'").Includes("fld", "<text/>\"\\'").NotIncludes("fld", "<text/>\"\\'").Eq("fld", "<text/>\"\\'").Geq("fld",
																																														   "<text/>\"\\'")
					.Gt("fld", "<text/>\"\\'").Leq("fld", "<text/>\"\\'").Lt("fld", "<text/>\"\\'").Neq("fld", "<text/>\"\\'").FormatQuery();
			Assert.AreEqual(
				@"<cgop><Eq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Eq><Neq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Neq><Contains><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Contains><BeginsWith><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></BeginsWith><In><FieldRef Name=""fld""/><Values><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Values></In><In><FieldRef Name=""fld""/><Values><Value Type=""Text"">&lt;text1/&gt;&quot;\&apos;</Value><Value Type=""Text"">&lt;text2/&gt;&quot;\&apos;</Value></Values></In><Includes><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Includes><NotIncludes><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></NotIncludes><Eq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Eq><Geq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Geq><GT><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></GT><Leq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Leq><LT><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></LT><Neq><FieldRef Name=""fld""/><Value Type=""Text"">&lt;text/&gt;&quot;\&apos;</Value></Neq></cgop>",
				ccg3r1);

			var cob1 = new CamlQueryBuilderOrderBy<Entity>().FormatQuery();
			var cob2 = new CamlQueryBuilderOrderBy<Entity>().Asc("fldA").FormatQuery();
			var cob3 = new CamlQueryBuilderOrderBy<Entity>().Asc("fldA").Desc("fldD").Asc("AfldA").FormatQuery();

			Assert.AreEqual(@"", cob1);
			Assert.AreEqual(@"<OrderBy><FieldRef Name=""fldA"" Ascending=""TRUE"" /></OrderBy>", cob2);
			Assert.AreEqual(@"<OrderBy><FieldRef Name=""fldA"" Ascending=""TRUE"" /><FieldRef Name=""fldD"" Ascending=""FALSE"" /><FieldRef Name=""AfldA"" Ascending=""TRUE"" /></OrderBy>",
							cob3);

			var cgb1 = new CamlQueryBuilderGroupBy<Entity>().FormatQuery();
			var cgb2 = new CamlQueryBuilderGroupBy<Entity>().Field("fldA").FormatQuery();
			var cgb3 = new CamlQueryBuilderGroupBy<Entity>().Field("fldA").Field("fldB").Field("fldC").FormatQuery();
			var cgb4 = new CamlQueryBuilderGroupBy<Entity>().Field("fldA").Field("fldB").Field("fldC").Set(false).FormatQuery();
			var cgb5 = new CamlQueryBuilderGroupBy<Entity>().Field("fldA").Field("fldB").Field("fldC").Set(50).FormatQuery();
			var cgb6 = new CamlQueryBuilderGroupBy<Entity>().Field("fldA").Field("fldB").Field("fldC").Set(false, 50).FormatQuery();

			Assert.AreEqual(@"", cgb1);
			Assert.AreEqual(@"<GroupBy Collapse=""TRUE"" GroupLimit=""100"" ><FieldRef Name=""fldA"" /></GroupBy>", cgb2);
			Assert.AreEqual(@"<GroupBy Collapse=""TRUE"" GroupLimit=""100"" ><FieldRef Name=""fldA"" /><FieldRef Name=""fldB"" /><FieldRef Name=""fldC"" /></GroupBy>", cgb3);
			Assert.AreEqual(@"<GroupBy Collapse=""FALSE"" GroupLimit=""100"" ><FieldRef Name=""fldA"" /><FieldRef Name=""fldB"" /><FieldRef Name=""fldC"" /></GroupBy>", cgb4);
			Assert.AreEqual(@"<GroupBy Collapse=""TRUE"" GroupLimit=""50"" ><FieldRef Name=""fldA"" /><FieldRef Name=""fldB"" /><FieldRef Name=""fldC"" /></GroupBy>", cgb5);
			Assert.AreEqual(@"<GroupBy Collapse=""FALSE"" GroupLimit=""50"" ><FieldRef Name=""fldA"" /><FieldRef Name=""fldB"" /><FieldRef Name=""fldC"" /></GroupBy>", cgb6);

			var cw1 = new CamlQueryBuilderWhere<Entity>().FormatQuery();
			var cw2 = new CamlQueryBuilderWhere<Entity>().Eq("fld", 1).FormatQuery();
			var cw3 = new CamlQueryBuilderWhere<Entity>().Eq("fld", 1).Eq("fld", 2).FormatQuery();
			var cw4 = new CamlQueryBuilderWhere<Entity>().Eq("fld", 1).Eq("fld", 2).Eq("fld", 3).FormatQuery();

			Assert.AreEqual(@"", cw1);
			Assert.AreEqual(@"<Where><Eq><FieldRef Name=""fld""/><Value Type=""Integer"">1</Value></Eq></Where>", cw2);
			Assert.AreEqual(
				@"<Where><And><Eq><FieldRef Name=""fld""/><Value Type=""Integer"">1</Value></Eq><Eq><FieldRef Name=""fld""/><Value Type=""Integer"">2</Value></Eq></And></Where>", cw3);
			Assert.AreEqual(
				@"<Where><And><And><Eq><FieldRef Name=""fld""/><Value Type=""Integer"">1</Value></Eq><Eq><FieldRef Name=""fld""/><Value Type=""Integer"">2</Value></Eq></And><Eq><FieldRef Name=""fld""/><Value Type=""Integer"">3</Value></Eq></And></Where>",
				cw4);
		}
	}
}